package Thread.ThreadSynchronization;

/*
 * Author: JacksonCoder
 * FileName: JoinMethod
 * Version: 1.0.0
 * Date: 2025/1/23
 */

public class JoinMethod {

    public static void main(String[] args) {
        // 创建三个线程
        Thread t1 = new Thread(() -> {
            System.out.println("Thread 1 started");
        });

        Thread t2 = new Thread(() -> {
            try {
                t1.join();
                System.out.println("T2 is running");
            } catch (InterruptedException e) {
                System.out.println("T2 is interrupted");
            }
        });

        Thread t3 = new Thread(() -> {
            try {
                t2.join();
                System.out.println("T3 is running");
            } catch (InterruptedException e) {
                System.out.println("T3 is interrupted");
            }
        });

        // 启动三个线程
        t1.start();
        t2.start();
        t3.start();

        // 主线程等待t3wanc
        try {
            t3.join();
            System.out.println("this is main");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println("All threads have finished execution");

    }

}
